package tt.com.carmanager.Handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author BEAN
 * @version 2020
 * @date 2022/8/25 15:55
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    // 插入时填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
//        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐使用)
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("lastUpdateTime", new Date(), metaObject);

    }

    // 填充时填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
//        this.fillStrategy(metaObject, "deleteTime", new Date()); // 起始版本 3.3.0(推荐)
//        this.setFieldValByName("deleteTime", new Date(), metaObject);
        this.setFieldValByName("lastUpdateTime", new Date(), metaObject);
    }

}
